/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "zobjects_gtk.h"

ZlangInvokeFunction ZlangInvokeFunction_guicolorchooserdialog_ModalOpenDialog_guiwindow_string;
int ZlangInvokeFunction_guicolorchooserdialog_ModalOpenDialog_guiwindow_string( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guicolorchooserdialog	*guicolorchooserdialog_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject					*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject					*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject					*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	struct ZlangDirectProperty_guiwindow			*guiwindow_direct_prop = GetObjectDirectProperty(in1) ;
	struct ZlangDirectProperty_guiwidget_common		*guiwindow_common = (struct ZlangDirectProperty_guiwidget_common *)guiwindow_direct_prop ;
	char							*title = NULL ;
	GdkRGBA							color ;
	
	CallRuntimeFunction_string_GetStringValue( rt , in2 , & title , NULL );

	guicolorchooserdialog_direct_prop->gtk_dialog = gtk_color_chooser_dialog_new( title , GTK_WINDOW(guiwindow_common->gtk_widget) ) ;
	guicolorchooserdialog_direct_prop->response = GtkDialogRun( rt , GTK_DIALOG(guicolorchooserdialog_direct_prop->gtk_dialog) ) ;
	if( guicolorchooserdialog_direct_prop->response == GTK_RESPONSE_OK )
	{
		gtk_color_chooser_get_rgba( GTK_COLOR_CHOOSER(guicolorchooserdialog_direct_prop->gtk_dialog) , & color );
		guicolorchooserdialog_direct_prop->alpha = (int32_t)(color.alpha*255) ;
		guicolorchooserdialog_direct_prop->red = (int32_t)(color.red*255) ;
		guicolorchooserdialog_direct_prop->green = (int32_t)(color.green*255) ;
		guicolorchooserdialog_direct_prop->blue = (int32_t)(color.blue*255) ;
	}
	CallRuntimeFunction_int_SetIntValue( rt , out1 , guicolorchooserdialog_direct_prop->response );
	
	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guicolorchooserdialog_ModalOpenDialog_guiwindow_string_int_int_int_int;
int ZlangInvokeFunction_guicolorchooserdialog_ModalOpenDialog_guiwindow_string_int_int_int_int( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guicolorchooserdialog	*guicolorchooserdialog_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject					*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject					*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject					*in3 = GetInputParameterInLocalObjectStack(rt,3) ;
	struct ZlangObject					*in4 = GetInputParameterInLocalObjectStack(rt,4) ;
	struct ZlangObject					*in5 = GetInputParameterInLocalObjectStack(rt,5) ;
	struct ZlangObject					*in6 = GetInputParameterInLocalObjectStack(rt,6) ;
	struct ZlangObject					*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	struct ZlangDirectProperty_guiwindow			*guiwindow_direct_prop = GetObjectDirectProperty(in1) ;
	struct ZlangDirectProperty_guiwidget_common		*guiwindow_common = (struct ZlangDirectProperty_guiwidget_common *)guiwindow_direct_prop ;
	char							*title = NULL ;
	int32_t							alpha ;
	int32_t							red ;
	int32_t							green ;
	int32_t							blue ;
	GdkRGBA							color ;
	
	CallRuntimeFunction_string_GetStringValue( rt , in2 , & title , NULL );
	CallRuntimeFunction_int_GetIntValue( rt , in3 , & alpha );
	CallRuntimeFunction_int_GetIntValue( rt , in4 , & red );
	CallRuntimeFunction_int_GetIntValue( rt , in5 , & green );
	CallRuntimeFunction_int_GetIntValue( rt , in6 , & blue );

	guicolorchooserdialog_direct_prop->gtk_dialog = gtk_color_chooser_dialog_new( title , GTK_WINDOW(guiwindow_common->gtk_widget) ) ;
	color.alpha = (float)alpha / 255 ;
	color.red = (float)red / 255 ;
	color.green = (float)green / 255 ;
	color.blue = (float)blue / 255 ;
	gtk_color_chooser_set_rgba( GTK_COLOR_CHOOSER(guicolorchooserdialog_direct_prop->gtk_dialog) , & color );
	guicolorchooserdialog_direct_prop->response = GtkDialogRun( rt , GTK_DIALOG(guicolorchooserdialog_direct_prop->gtk_dialog) ) ;
	if( guicolorchooserdialog_direct_prop->response == GTK_RESPONSE_OK )
	{
		gtk_color_chooser_get_rgba( GTK_COLOR_CHOOSER(guicolorchooserdialog_direct_prop->gtk_dialog) , & color );
		guicolorchooserdialog_direct_prop->alpha = (int32_t)(color.alpha*255) ;
		guicolorchooserdialog_direct_prop->red = (int32_t)(color.red*255) ;
		guicolorchooserdialog_direct_prop->green = (int32_t)(color.green*255) ;
		guicolorchooserdialog_direct_prop->blue = (int32_t)(color.blue*255) ;
	}
	CallRuntimeFunction_int_SetIntValue( rt , out1 , guicolorchooserdialog_direct_prop->response );
	
	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guicolorchooserdialog_GetAlpha;
int ZlangInvokeFunction_guicolorchooserdialog_GetAlpha( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guicolorchooserdialog	*guicolorchooserdialog_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject					*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	
	CallRuntimeFunction_int_SetIntValue( rt , out1 , guicolorchooserdialog_direct_prop->alpha );
	
	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guicolorchooserdialog_GetRed;
int ZlangInvokeFunction_guicolorchooserdialog_GetRed( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guicolorchooserdialog	*guicolorchooserdialog_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject					*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	
	CallRuntimeFunction_int_SetIntValue( rt , out1 , guicolorchooserdialog_direct_prop->red );
	
	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guicolorchooserdialog_GetGreen;
int ZlangInvokeFunction_guicolorchooserdialog_GetGreen( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guicolorchooserdialog	*guicolorchooserdialog_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject					*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	
	CallRuntimeFunction_int_SetIntValue( rt , out1 , guicolorchooserdialog_direct_prop->green );
	
	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guicolorchooserdialog_GetBlue;
int ZlangInvokeFunction_guicolorchooserdialog_GetBlue( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guicolorchooserdialog	*guicolorchooserdialog_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject					*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	
	CallRuntimeFunction_int_SetIntValue( rt , out1 , guicolorchooserdialog_direct_prop->blue );
	
	return 0;
}

ZlangCreateDirectPropertyFunction ZlangCreateDirectProperty_guicolorchooserdialog;
void *ZlangCreateDirectProperty_guicolorchooserdialog( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guicolorchooserdialog	*guicolorchooserdialog_prop = NULL ;
	
	guicolorchooserdialog_prop = (struct ZlangDirectProperty_guicolorchooserdialog *)ZLMALLOC( sizeof(struct ZlangDirectProperty_guicolorchooserdialog) ) ;
	if( guicolorchooserdialog_prop == NULL )
	{
		SET_RUNTIME_ERROR( rt , RUNTIME_ERROR , ZLANG_ERROR_ALLOC , "alloc memory for entity" )
		return NULL;
	}
	memset( guicolorchooserdialog_prop , 0x00 , sizeof(struct ZlangDirectProperty_guicolorchooserdialog) );
	
	return guicolorchooserdialog_prop;
}

ZlangDestroyDirectPropertyFunction ZlangDestroyDirectProperty_guicolorchooserdialog;
void ZlangDestroyDirectProperty_guicolorchooserdialog( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guicolorchooserdialog	*guicolorchooserdialog_direct_prop = GetObjectDirectProperty(obj) ;
	
	ZLFREE( guicolorchooserdialog_direct_prop );
	
	return;
}

ZlangSummarizeDirectPropertySizeFunction ZlangSummarizeDirectPropertySize_guicolorchooserdialog;
void ZlangSummarizeDirectPropertySize_guicolorchooserdialog( struct ZlangRuntime *rt , struct ZlangObject *obj , size_t *summarized_obj_size , size_t *summarized_direct_prop_size )
{
	SUMMARIZE_SIZE( summarized_direct_prop_size , sizeof(struct ZlangDirectProperty_guicolorchooserdialog) )
	return;
}

static struct ZlangDirectFunctions direct_funcs_guicolorchooserdialog =
	{
		ZLANG_OBJECT_guicolorchooserdialog , /* char *ancestor_name */
		
		ZlangCreateDirectProperty_guicolorchooserdialog , /* ZlangCreateDirectPropertyFunction *create_entity_func */
		ZlangDestroyDirectProperty_guicolorchooserdialog , /* ZlangDestroyDirectPropertyFunction *destroy_entity_func */
		
		NULL , /* ZlangFromCharPtrFunction *from_char_ptr_func */
		NULL , /* ZlangToStringFunction *to_string_func */
		NULL , /* ZlangFromDataPtrFunction *from_data_ptr_func */
		NULL , /* ZlangGetDataPtrFunction *get_data_ptr_func */
		
		NULL , /* ZlangOperatorFunction *oper_PLUS_func */
		NULL , /* ZlangOperatorFunction *oper_MINUS_func */
		NULL , /* ZlangOperatorFunction *oper_MUL_func */
		NULL , /* ZlangOperatorFunction *oper_DIV_func */
		NULL , /* ZlangOperatorFunction *oper_MOD_func */
		
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_NEGATIVE_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_NOT_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_BIT_REVERSE_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_PLUS_PLUS_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_MINUS_MINUS_func */
		
		NULL , /* ZlangCompareFunction *comp_EGUAL_func */
		NULL , /* ZlangCompareFunction *comp_NOTEGUAL_func */
		NULL , /* ZlangCompareFunction *comp_LT_func */
		NULL , /* ZlangCompareFunction *comp_LE_func */
		NULL , /* ZlangCompareFunction *comp_GT_func */
		NULL , /* ZlangCompareFunction *comp_GE_func */
		
		NULL , /* ZlangLogicFunction *logic_AND_func */
		NULL , /* ZlangLogicFunction *logic_OR_func */
		
		NULL , /* ZlangLogicFunction *bit_AND_func */
		NULL , /* ZlangLogicFunction *bit_XOR_func */
		NULL , /* ZlangLogicFunction *bit_OR_func */
		NULL , /* ZlangLogicFunction *bit_MOVELEFT_func */
		NULL , /* ZlangLogicFunction *bit_MOVERIGHT_func */
		
		ZlangSummarizeDirectPropertySize_guicolorchooserdialog , /* ZlangSummarizeDirectPropertySizeFunction *summarize_direct_prop_size_func */
	} ;

ZlangImportObjectFunction ZlangImportObject_guicolorchooserdialog;
struct ZlangObject *ZlangImportObject_guicolorchooserdialog( struct ZlangRuntime *rt )
{
	struct ZlangObject	*obj = NULL ;
	struct ZlangFunction	*func = NULL ;
	int			nret = 0 ;
	
	nret = ImportObject( rt , & obj , ZLANG_OBJECT_guicolorchooserdialog , & direct_funcs_guicolorchooserdialog , sizeof(struct ZlangDirectFunctions) , NULL ) ;
	if( nret )
	{
		SET_RUNTIME_ERROR( rt , RUNTIME_ERROR , ZLANG_ERROR_LINK_FUNC_TO_ENTITY , "import object to global objects heap" )
		return NULL;
	}
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guicolorchooserdialog_ModalOpenDialog_guiwindow_string , ZLANG_OBJECT_int , "ModalOpenDialog" , ZLANG_OBJECT_guiwindow,NULL , ZLANG_OBJECT_string,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guicolorchooserdialog_ModalOpenDialog_guiwindow_string_int_int_int_int , ZLANG_OBJECT_int , "ModalOpenDialog" , ZLANG_OBJECT_guiwindow,NULL , ZLANG_OBJECT_string,NULL , ZLANG_OBJECT_int,NULL , ZLANG_OBJECT_int,NULL , ZLANG_OBJECT_int,NULL , ZLANG_OBJECT_int,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guicolorchooserdialog_GetAlpha , ZLANG_OBJECT_int , "GetAlpha" , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guicolorchooserdialog_GetRed , ZLANG_OBJECT_int , "GetRed" , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guicolorchooserdialog_GetGreen , ZLANG_OBJECT_int , "GetGreen" , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guicolorchooserdialog_GetBlue , ZLANG_OBJECT_int , "GetBlue" , NULL ) ;
	if( func == NULL )
		return NULL;
	
	return obj ;
}

